/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import parsePhoneNumber from "./source/parsePhoneNumber.js";
import AsYouType from "./source/AsYouType.js"
import findPhoneNumbersInText from "./source/findPhoneNumbersInText.js"
import ParseError from './source/ParseError.js';

import { customData } from "./customData.js"; // user-defined metadata
import Log from './log.js';

import metadata from './metadata.min.json.js'
import formatNumber from './source/format.js'
import format from './source/format.js'
import parseNumber from './source/parse.js'
import parse from './source/parse.js'
import parsePhoneNumberFromString from './source/parsePhoneNumberFromString.js'
import isValidPhoneNumber from './source/isValidPhoneNumber.js'
import isPossiblePhoneNumber from './source/isPossibleNumber.js'
import isValidNumber from './source/validate.js'
import isPossibleNumber from './source/isPossibleNumber.js';
import validatePhoneNumberLength from './source/validatePhoneNumberLength.js'
import isValidNumberForRegion from './source/isValidNumberForRegion.js'
import examples from './examples.mobile.json.js'
import getExampleNumber from './source/getExampleNumber.js'
import getNumberType from './source/getNumberType.js'
import findNumbers from './source/findNumbers.js'
import searchNumbers from './source/searchNumbers.js'
import { jsonData } from './data.js'

const TAG = "PHONENUMBER  ";

const contacts = JSON.parse(jsonData).contacts;
const number = contacts[0].phoneNumber;
const phoneNumber = parsePhoneNumber(number, contacts[0].country, metadata);
const asYouType = new AsYouType(contacts[0].country, metadata);

const findPhoneNumbers = 'For tech support call +7 (800) 555-35-35 internationally or reach a local US branch at (213) 373-4253 ext. 1234.';
const numbers = ['+8618717452985', '+12133734253', '+78005553535'];

const forNumberPro = 10000000;
const forNumber = 1000000;
const forNumber1 = 100000;
const forNumber2 = 10000;
const forNumber3 = 1000;

//number
function getNumber_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        element = phoneNumber.number.toString();
    }
    let endTime = Date.now();
    // 号码, 譬如 +12133734253
    // Log.showInfo(TAG + 'number：' + phoneNumber.number.toString())
    if (element != '+12133734253') throw Error(`getNumber element != '+12133734253'`);
    Log.showInfo(`Libphonenumber_number: ${endTime - startTime} ms`);
}
//phoneNumber country
function country_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        element = phoneNumber.country;
    }
    // 国家，譬如 US
    // Log.showInfo(TAG + 'country：' + phoneNumber.country);
    let endTime = Date.now();
    if (element != 'US') throw Error(`country element != 'US'`);
    Log.showInfo(`Libphonenumber_country: ${endTime - startTime} ms`);
}
//phoneNumber formatNational
function national_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = phoneNumber.formatNational();
    }
    // 国内的号码样式，譬如 (213) 373-4253
    // Log.showInfo(TAG + 'national：' + phoneNumber.formatNational());
    let endTime = Date.now();
    if (element != '(213) 373-4253') throw Error(`national element != '(213) 373-4253'`);
    Log.showInfo(`Libphonenumber_national: ${endTime - startTime} ms`);
}
//phoneNumber formatInternational
function international_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = phoneNumber.formatInternational();
    }
    // 国内的号码样式，譬如 (213) 373-4253
    // Log.showInfo(TAG + 'international：' + phoneNumber.formatInternational());
    let endTime = Date.now();
    if (element != '+1 213 373 4253') throw Error(`international element != '+1 213 373 4253'`);
    Log.showInfo(`Libphonenumber_international: ${endTime - startTime} ms`);
}
//phoneNumber getURI
function uri_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = phoneNumber.getURI();
    }
    // uri形式的样式，譬如 tel:+12133734253
    // Log.showInfo(TAG + 'uri：' + phoneNumber.getURI());
    let endTime = Date.now();
    if (element != 'tel:+12133734253') throw Error(`uri element != 'tel:+12133734253'`);
    Log.showInfo(`Libphonenumber_uri: ${endTime - startTime} ms`);
}
//phoneNumber getType
function type_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = phoneNumber.getType();
    }
    // 类型，譬如 FIXED_LINE_OR_MOBILE
    //  Log.showInfo(TAG + 'type：' + phoneNumber.getType());
    let endTime = Date.now();
    if (element != 'FIXED_LINE_OR_MOBILE') throw Error(`type element != 'FIXED_LINE_OR_MOBILE'`);
    Log.showInfo(`Libphonenumber_type: ${endTime - startTime} ms`);
}
//phoneNumber isPossible
function isPossible_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber1; i++) {
        element = phoneNumber.isPossible();
    }
    // 是否可能是号码，从数字个数上进行判断
    // Log.showInfo(TAG + 'isPossible：' + phoneNumber.isPossible());
    let endTime = Date.now();
    if (element != true) throw Error(`isPossible element != true`);
    Log.showInfo(`Libphonenumber_isPossible: ${endTime - startTime} ms`);
}
// phoneNumber isValid
function isValid_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = phoneNumber.isValid();
    }
    // 是否是有效号码，从所有匹配原则上判断
    //  Log.showInfo(TAG + 'isValid：' + phoneNumber.isValid());
    let endTime = Date.now();
    if (element != true) throw Error(`isValid element != true`);
    Log.showInfo(`Libphonenumber_isValid(true): ${endTime - startTime} ms`);
}

// number input analysis
function input_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = new AsYouType('US', metadata).input(number);
    }
    // 当你键入一个数字时，与之前键入的数字连接起来一起解析，直到调用clear清除状态
    //  asYouType.input(number);
    let endTime = Date.now();
    if (element != '(213) 373-4253') throw Error(`input element != '(213) 373-4253'`);
    Log.showInfo(`Libphonenumber_input: ${endTime - startTime} ms`);
}
asYouType.input(number);
//analysis getCountry
function getCountry_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumberPro; i++) {
        element = asYouType.getCountry();
    }
    // 根据你键入的数字,解析国家，譬如 US
    // Log.showInfo(TAG + 'country：' + asYouType.getCountry());
    let endTime = Date.now();
    if (element != 'US') throw Error(`getCountry element != 'US'`);
    Log.showInfo(`Libphonenumber_getCountry: ${endTime - startTime} ms`);
}
//analysis getTemplate
function getTemplate_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber1; i++) {
        element = asYouType.getTemplate();
    }
    // 根据你键入的数字,解析模板，譬如 (xxx) xxx-xxxx
    // Log.showInfo(TAG + 'template：' + asYouType.getTemplate());
    let endTime = Date.now();
    if (element != '(xxx) xxx-xxxx') throw Error(`getTemplate element != '(xxx) xxx-xxxx'`);
    Log.showInfo(`Libphonenumber_getTemplate: ${endTime - startTime} ms`);
}

//analysis getNumber
function getNumber_test_02() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber1; i++) {
        element = asYouType.getNumber();
    }
    let endTime = Date.now();
    if (element.country != 'US') throw Error(`getNumber lement.country != 'US'`);
    Log.showInfo(`Libphonenumber_getNumber: ${endTime - startTime} ms`);
}

const phoneNumberValue = asYouType.getNumber();
//analysis formatNational
function formatNational_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = phoneNumberValue.formatNational();
    }
    // 根据你键入的数字,解析国内的号码样式，譬如 (213) 373-4253
    //   Log.showInfo(TAG + 'national：' + phoneNumberValue.formatNational());
    let endTime = Date.now();
    if (element != '(213) 373-4253') throw Error(`asFormatNational element != '(213) 373-4253'`);
    Log.showInfo(`Libphonenumber_formatNational: ${endTime - startTime} ms`);
}
//search phoneNumber
function findPhoneNumbersInText_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = findPhoneNumbersInText(findPhoneNumbers, 'US', "US", metadata);
    }
    //从一段文本中查找出电话号码
    let endTime = Date.now();
    if (element[0].number.number != '+78005553535') throw Error(`asFindPhoneNumbersInText element != '+78005553535'`);
    Log.showInfo(`Libphonenumber_findPhoneNumbersInText: ${endTime - startTime} ms`);
}

//search phoneNumber
function parsePhoneNumber_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = parsePhoneNumber(numbers[0], customData, metadata);
    }
    let endTime = Date.now();
    if (element.number != '+8618717452985') throw Error(`asParsePhoneNumber element != '+8618717452985'`);
    Log.showInfo(`Libphonenumber_parsePhoneNumber: ${endTime - startTime} ms`);
}

// analysis 
function reset_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = asYouType.reset().input(number);
    }
    let endTime = Date.now();
    if (element != '(213) 373-4253') throw Error(`reset element != '(213) 373-4253'`);
    Log.showInfo(`Libphonenumber_reset: ${endTime - startTime} ms`);
}

function getNumberValue_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        element = asYouType.getNumberValue();
    }
    let endTime = Date.now();
    if (element != '+12133734253') throw Error(`getNumberValue element != '+12133734253'`);
    Log.showInfo(`Libphonenumber_getNumberValue: ${endTime - startTime} ms`);
}
function getNationalNumber_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumberPro; i++) {
        element = asYouType.getNationalNumber();
    }
    let endTime = Date.now();

    if (element != '2133734253') throw Error(`getNationalNumber element != '2133734253'`);
    Log.showInfo(`Libphonenumber_getNationalNumber: ${endTime - startTime} ms`);
}
function getChars_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        element = asYouType.getChars();
    }
    let endTime = Date.now();

    if (element != '2133734253') throw Error(`getChars element != '2133734253'`);
    Log.showInfo(`Libphonenumber_getChars: ${endTime - startTime} ms`);
}
function getCallingCode_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        //呼叫码
        element = asYouType.getCallingCode();
    }
    let endTime = Date.now();
    if (element != undefined) throw Error(`getCallingCode element != undefined`);
    Log.showInfo(`Libphonenumber_getCallingCode: ${endTime - startTime} ms`);
}
function isInternational_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        //国际号
        element = asYouType.isInternational();
    }
    let endTime = Date.now();
    if (element != false) throw Error(`isInternational element != false`);
    Log.showInfo(`Libphonenumber_isInternational: ${endTime - startTime} ms`);
}
function format_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber1; i++) {
        //格式化号码
        element = format({
            country: 'US',
            phone: '2133734253',
            ext: '123'
        }, 'RFC3966', metadata);
    }
    let endTime = Date.now();
    if (element != 'tel:+12133734253;ext=123') throw Error(`format1 element != 'tel:+12133734253;ext=123'`);
    Log.showInfo(`Libphonenumber_format: ${endTime - startTime} ms`);
}

function parse_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = JSON.stringify(parse('(800) 55 35 35', {
            defaultCountry: 'RU'
        }, metadata))
    }
    let endTime = Date.now();
    if (element != "{}") throw Error(`parse element != '{}'`);
    Log.showInfo(`Libphonenumber_parse: ${endTime - startTime} ms`);
}
function parseNumber_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = JSON.stringify(parseNumber('(800) 55 35 35', {
            defaultCountry: 'RU'
        }, metadata))
    }
    let endTime = Date.now();
    if (element != "{}") throw Error(`parseNumber element != {}`);
    Log.showInfo(`Libphonenumber_parseNumber: ${endTime - startTime} ms`);
}
function parsePhoneNumberFromString_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        //解析号码
        element = parsePhoneNumberFromString('(213) 373-4253', {
            extract: false,
            defaultCountry: 'US'
        }, metadata)
    }
    let endTime = Date.now();
    if (element == undefined) throw Error(`parsePhoneNumberFromString element == undefined`);
    Log.showInfo(`Libphonenumber_parsePhoneNumberFromString: ${endTime - startTime} ms`);
}

function isValidPhoneNumber_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        element = isValidPhoneNumber('8 (800) 555 35 35', 'RU', metadata)
    }
    let endTime = Date.now();
    if (element != true) throw Error(`isValidPhoneNumber element != true`);
    Log.showInfo(`Libphonenumber_isValidPhoneNumber: ${endTime - startTime} ms`);
}
function isPossiblePhoneNumber_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = isPossiblePhoneNumber('+7 (800) 555 35 35', metadata)
    }
    let endTime = Date.now();
    if (element != true) throw Error(`isPossiblePhoneNumber element != false`);
    Log.showInfo(`Libphonenumber_isPossiblePhoneNumber: ${endTime - startTime} ms`);
}
function isValidNumber_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = isValidNumber('(213) 37', 'US', metadata)
    }
    let endTime = Date.now();
    if (element != false) throw Error(`isValidNumber element != false`);
    Log.showInfo(`Libphonenumber_isValidNumber: ${endTime - startTime} ms`);
}
function isPossibleNumber_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = isPossibleNumber('+79992223344', metadata)
    }
    let endTime = Date.now();
    if (element != true) throw Error(`isPossibleNumber element != true`);
    Log.showInfo(`Libphonenumber_isPossibleNumber(true): ${endTime - startTime} ms`);
}
function validatePhoneNumberLength_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = validatePhoneNumberLength('444 1 44', 'TR', metadata)
    }
    let endTime = Date.now();
    if (element != 'TOO_SHORT') throw Error(`validatePhoneNumberLength element != false`);
    Log.showInfo(`Libphonenumber_validatePhoneNumberLength: ${endTime - startTime} ms`);
}

function formatNumber_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        //验证号码格式
        element = formatNumber('+12111111111', 'NATIONAL', metadata)
    }
    let endTime = Date.now();
    if (element != '(211) 111-1111') throw Error(`formatNumber element != '(211) 111-1111'`);
    Log.showInfo(`Libphonenumber_formatNumber: ${endTime - startTime} ms`);
}
function isValidNumberForRegion_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = isValidNumberForRegion('07624369230', 'GB', metadata)
    }
    let endTime = Date.now();
    if (element != false) throw Error(`isValidNumberForRegion element != false`);
    Log.showInfo(`Libphonenumber_isValidNumberForRegion: ${endTime - startTime} ms`);
}
function getExampleNumber_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        //示例编号
        element = getExampleNumber('RU', examples, metadata);
    }
    let endTime = Date.now();
    if (element.nationalNumber != '9123456789') throw Error(`getExampleNumber element != '9123456789'`);
    Log.showInfo(`Libphonenumber_getExampleNumber: ${endTime - startTime} ms`);
}

function getNumberType_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = getNumberType({
            country: 'US',
            phone: '2133734253'
        }, metadata);
    }
    let endTime = Date.now();
    if (element != "FIXED_LINE_OR_MOBILE") throw Error(`getNumberType element != "FIXED_LINE_OR_MOBILE"`);
    Log.showInfo(`Libphonenumber_getNumberType: ${endTime - startTime} ms`);
}

function findNumbers_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        element = findNumbers('The number is +7 (800) 555-35-35 as written in the document.', 'US', metadata);
    }
    let endTime = Date.now();
    if (element[0].phone != '8005553535') throw Error(`findNumbers element != '8005553535'`);
    Log.showInfo(`Libphonenumber_findNumbers: ${endTime - startTime} ms`);
}
const searchNumbersText = "The number is +7 (800) 555-35-35 and not (213) 373-4253 as written in the document.";
function searchNumbers_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        let result = searchNumbers(searchNumbersText, "US", metadata);
        const iterator = result[Symbol.iterator]();
        element = iterator.next();
    }
    let endTime = Date.now();
    if (element.value.phone != '8005553535') throw Error(`searchNumbers element != `);
    Log.showInfo(`Libphonenumber_searchNumbers: ${endTime - startTime} ms`);
}
function isEqual_test() {
    let element;
    const phoneNumber1 = parsePhoneNumber("8005553535", "RU", metadata);
    const phoneNumber2 = parsePhoneNumber("5555553535", "RU", metadata);
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        element = phoneNumber1.isEqual(phoneNumber2, 'RU', metadata);
    }
    let endTime = Date.now();
    if (element != false) throw Error(`isEqual element != "false"`);
    Log.showInfo(`Libphonenumber_isEqual(number): ${endTime - startTime} ms`);
}

function isEqual_test_02() {
    let element;
    const phoneNumber1 = parsePhoneNumber("+12133734253", "US", metadata);
    const phoneNumber2 = parsePhoneNumber("8003535", "RU", metadata);
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        element = phoneNumber1.isEqual(phoneNumber2, metadata);
    }
    let endTime = Date.now();
    if (element != false) throw Error(`isEqual element != "false"`);
    Log.showInfo(`Libphonenumber_isEqual(country): ${endTime - startTime} ms`);
}

function setExt_test() {
    //解析号码
    const phoneNumber3 = parsePhoneNumberFromString('2345678', {
        defaultCallingCode: "1", defaultCountry: "US"
    }, metadata);
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        phoneNumber3.setExt('1234', metadata);
        element = phoneNumber3.ext
    }
    let endTime = Date.now();
    if (element != '1234') throw Error(`setExt element != '1234'`);
    Log.showInfo(`Libphonenumber_setExt: ${endTime - startTime} ms`);
}

function isValid_test_02() {

    const phoneNumber2 = parsePhoneNumberFromString('2345678', {
        defaultCallingCode: "1", defaultCountry: "US"
    }, metadata);
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber1; i++) {
        element = phoneNumber2.isValid();
    }
    let endTime = Date.now();
    if (element != false) throw Error(`isValid element != false`);
    Log.showInfo(`Libphonenumber_isValid(false): ${endTime - startTime} ms`);
}
function getType_test_02() {
    const phoneNumber2 = parsePhoneNumberFromString('2345678', {
        defaultCallingCode: "1", defaultCountry: "US"
    }, metadata);
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber1 ; i++) {
        element = phoneNumber2.getType();
    }
    let endTime = Date.now();
    if (element != undefined) throw Error(`getType element != undefined`);
    Log.showInfo(`Libphonenumber_getType: ${endTime - startTime} ms`);
}
function isPossible_test_02() {
    const phoneNumber3 = parsePhoneNumberFromString('3734253', "US", metadata);
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        element = phoneNumber3.isPossible();
    }
    let endTime = Date.now();
    if (element != false) throw Error(`isPossible element != false`);
    Log.showInfo(`Libphonenumber_isPossible(false): ${endTime - startTime} ms`);
}
function isNonGeographic_test() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber1; i++) {
        element = phoneNumber.isNonGeographic();
    }
    let endTime = Date.now();
    if (element != false) throw Error(`isNonGeographic element != false`);
    Log.showInfo(`Libphonenumber_isNonGeographic: ${endTime - startTime} ms`);
}

function format_test_02() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        element = format('2133734253', 'US', 'E.164', metadata);
    }
    let endTime = Date.now();
    if (element != '+12133734253') throw Error(`format1 element != '+12133734253'`);
    Log.showInfo(`Libphonenumber_test_format(parameter): ${endTime - startTime} ms`);
}
function parse_test_02() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = JSON.stringify(parse('+9664', {
            extended: true
        }, metadata))
    }
    let endTime = Date.now();
    if (element != "{}") throw Error(`parse element != {}`);
    Log.showInfo(`Libphonenumber_test_parse(string,bool): ${endTime - startTime} ms`);
}
function formatNumber_test_02() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        element = formatNumber({
            country: 'US',
            phone: '2133734253',
            ext: '123'
        }, 'RFC3966', metadata)
    }
    let endTime = Date.now();
    if (element != 'tel:+12133734253;ext=123') throw Error(`formatNumber3 element != 'tel:+12133734253;ext=123'`);
    Log.showInfo(`Libphonenumber_formatNumber(Map): ${endTime - startTime} ms`);

}
//search phoneNumber
function findPhoneNumbersInText_test_02() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        element = findPhoneNumbersInText(findPhoneNumbers, 'US',  metadata);
    }
    //从一段文本中查找出电话号码
    let endTime = Date.now();
    if (element[1].number.number != '+12133734253') throw Error(`asFindPhoneNumbersInText element != '+12133734253'`);
    Log.showInfo(`Libphonenumber_findPhoneNumbersInText(string,string): ${endTime - startTime} ms`);
}

function findNumbers_test_02() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        element = findNumbers(searchNumbersText, 'US', metadata);
    }
    let endTime = Date.now();
    if (element[0].phone != '8005553535') throw Error(`findNumbers element != '8005553535'`);
    Log.showInfo(`Libphonenumber_findNumbers(List): ${endTime - startTime} ms`);
}
function searchNumbers_test_02() {
    let element;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        let result = searchNumbers(searchNumbersText, {
            defaultCountry: "US", v2: true
        }, metadata);
        const iterator = result[Symbol.iterator]();
        element = iterator.next();
    }
    let endTime = Date.now();
    if (element.value.number.number != '+78005553535') throw Error(`searchNumbers element != '+78005553535'`);
    Log.showInfo(`Libphonenumber_test_searchNumbers(Map): ${endTime - startTime} ms`);
}
function isEqual_test_03() {
    let element;
    const phoneNumber1 = parsePhoneNumber("8005553535", "RU", metadata);
    const phoneNumber2 = parsePhoneNumber("8005553535", "RU", metadata);
    let startTime = Date.now();
    for (let i = 0; i < forNumber; i++) {
        element = phoneNumber1.isEqual(phoneNumber2, metadata);
    }
    let endTime = Date.now();
    if (element != true) throw Error(`isEqual element != true`);
    Log.showInfo(`Libphonenumber_isEqual(compare): ${endTime - startTime} ms`);
}

getNumber_test();
country_test();
national_test();
international_test();
uri_test();
type_test();
isPossible_test();
isValid_test();
input_test();
getCountry_test();
getTemplate_test();
getNumber_test_02();
formatNational_test();
findPhoneNumbersInText_test();
parsePhoneNumber_test();
reset_test();
getNumberValue_test();
getNationalNumber_test();
getChars_test();
getCallingCode_test();
isInternational_test();
format_test();
parse_test();
parseNumber_test();
parsePhoneNumberFromString_test();
isValidPhoneNumber_test();
isPossiblePhoneNumber_test();
isValidNumber_test();
isPossibleNumber_test();
validatePhoneNumberLength_test();
formatNumber_test();
isValidNumberForRegion_test();
getExampleNumber_test();
getNumberType_test();
findNumbers_test();
searchNumbers_test();
isEqual_test();
isEqual_test_02();
setExt_test();
isValid_test_02();
getType_test_02();
isPossible_test_02();
isNonGeographic_test();
format_test_02();
parse_test_02();
formatNumber_test_02();
findPhoneNumbersInText_test_02();
findNumbers_test_02();
searchNumbers_test_02();
isEqual_test_03();